package com.zhengxing.jienci.user.controller;

import com.zhengxing.jienci.web.util.file.FileUploadException;
import com.zhengxing.jienci.web.util.file.FileUploadUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 浪遏飞舟
 * @create 2020-10-31 15:45
 */
@RestController
@RequestMapping("/upload")
public class UploadController {

    @Autowired
    private FileUploadUtils fileUploadUtils;

    @RequestMapping("/file")
    public String uploadFile(MultipartFile file){
        try {
           String uploadPathName = fileUploadUtils.hashCodeSaveFile(file);
           return uploadPathName;
        } catch (FileUploadException e) {
            e.printStackTrace();
            return e.getMessage();
        }
    }

}
